package com.garen.sys.web;

import com.garen.sys.biz.IFireOrgBiz;
import com.garen.sys.entity.FireOrg;
import com.garen.sys.entity.FireUser;

import org.springframework.stereotype.Controller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.garen.common.*;
import org.springframework.web.servlet.ModelAndView;
import com.garen.sys.filter.SysFilter;


@Controller
@RequestMapping("/sys")
public final class FireOrgAction extends BaseAction{

	protected static Log log = LogFactory.getLog(FireOrgAction.class);

	@Autowired
	private IFireOrgBiz iFireOrgBiz;

	@RequestMapping("/fireorg/json") 
	public ModelAndView json(PageBean<FireOrg> pb,FireOrg fireOrg) {
		iFireOrgBiz.getFireOrgList(pb,fireOrg);
		return Json(pb);
	}

	@RequestMapping("/fireorg/get") 
	public ModelAndView json(FireOrg fireOrg) {
		MsgBean mbean = SysFilter.getMsgBean();
		if(fireOrg.getOrgId() == null) {
			mbean.setRetInfo(-1, "参数不能为空!");
		}else {
			mbean.setObj(iFireOrgBiz.getFireOrg(fireOrg));
		}
		return Json(mbean);
	}

	@RequestMapping("/fireorg/boxJson") 
	public ModelAndView boxJson(FireOrg fireOrg) {
		return Json(iFireOrgBiz.getFireOrgList(fireOrg));
	}
	
	@RequestMapping("/fireorg/tree") 
	public ModelAndView tree(FireOrg fireOrg) {
		MsgBean mbean = SysFilter.getMsgBean();
		FireUser user = getSessionUser();
		mbean.setObj(iFireOrgBiz.getFireOrgListByTree(mbean,fireOrg,user.getUserOrgId()));
		return Json(mbean);
	}

	
	@RequestMapping("/fireorg/orgList") 
	public ModelAndView orgList(FireOrg fireOrg) {
		MsgBean mbean = SysFilter.getMsgBean();
		FireUser user = getSessionUser();
		fireOrg.setOrgType(FireOrg.ORG_TYPE_LOCHUS);
		Integer orgId = fireOrg.getOrgId();
		if(orgId == null) orgId = user.getUserOrgId();
		mbean.setObj(iFireOrgBiz.getFireOrgListByType(fireOrg,orgId));
		return Json(mbean);
	}

	@RequestMapping("/fireorg/edit") 
	public ModelAndView edit(ModelAndView mav,FireOrg fireOrg) {
		mav.setViewName("sys/FireOrgEdit");
		if(fireOrg.getOrgId() != null){
			fireOrg=iFireOrgBiz.getFireOrg(fireOrg);
		}
		mav.addObject("fireOrg",fireOrg);
		return mav;
	}

	@RequestMapping("/fireorg/save") 
	public ModelAndView save(FireOrg fireOrg) {
		MsgBean mbean = SysFilter.getMsgBean(0, "保存成功 !");
		iFireOrgBiz.saveFireOrg(mbean,fireOrg);
		return Json(mbean);
	}

	@RequestMapping("/fireorg/del") 
	public ModelAndView del(FireOrg fireOrg) {
		MsgBean mbean = SysFilter.getMsgBean(0, "删除成功 !");
		iFireOrgBiz.delFireOrg(mbean,fireOrg);
		return Json(mbean);
	}

}
